<?php

namespace app\teacher\model;

use app\common\model\TeachingExperience as TeachingExperienceModel;
use think\Model;

class TeachingExperience extends TeachingExperienceModel
{

    /**
     * 新增经历
     */
    public static function add($teacherId, $experiences)
    {
        return self::insertAll(self::addData($teacherId, $experiences));
    }

    public static function addData($teacherId, $experiences)
    {
        $data = [];
        foreach ($experiences as $val) {
            $val['teacher_id'] = $teacherId;
            $val['starttime'] = strtotime($val['starttime']);
            $val['endtime'] = strtotime($val['endtime']);
            $val['createtime'] = time();
            $val['updatetime'] = time();
            $data[] = $val;
        }
        return $data;
    }

    /**
     * 删除经历
     */
    public static function deleteExperience($teacherId)
    {
        return self::where('teacher_id', $teacherId)->delete();
    }
}
